﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

namespace AUV5.Web.Manage
{
    public partial class ServiceVideoManage : PageBaseBackend
    {
        public string serviceid = HttpContext.Current.Request["serviceID"] ?? "";
        public Model.ServiceAttachment video = null;
        public string videopath = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (serviceid != "")
            {
                video = BLL.ServiceAttachmentBLL.Instance.GetVideo(serviceid);
                initVideo();
            }
        }

        //加载数据
        private void initVideo()
        {
            if (video != null)
            {
                videopath = video.VideoPath;
                if (video.State == (int)Common.Enum.auvState.Enabled)
                {
                    lbStatus.Text = "已审核";
                    btnPass.Visible = false;
                }
                else if (video.State == (int)Common.Enum.auvState.Disable)
                {
                    lbStatus.Text = "未审核";
                    btnPass.Visible = true;
                }
            }
            else
            {
                lbStatus.Text = "视频不存在或已删除";
                btnPass.Visible = false;
                btnDel.Visible = false;
            }
        }

        //通过审核
        protected void btnPass_Click(object sender, EventArgs e)
        {
            if (video != null)
            {
                video.State = (int)Common.Enum.auvState.Enabled;
                BLL.ServiceAttachmentBLL.Instance.Update(video);
                initVideo();
            }
        }

        //删除
        protected void btnDel_Click(object sender, EventArgs e)
        {
            if (video != null)
            {
                BLL.ServiceAttachmentBLL.Instance.Delete(video);
                //删除图片及缩略图
                if (File.Exists(Server.MapPath(video.VideoPath)))
                {
                    File.Delete(Server.MapPath(video.VideoPath));
                }
                if (File.Exists(Server.MapPath(video.ImagePath)))
                {
                    File.Delete(Server.MapPath(video.ImagePath));
                }
                video = null;
                initVideo();
            }
        }
    }
}